package com.evildog.workspace.invest.application.controller;

import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.common.object.PageQuery;
import java.util.List;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.invest.application.model.BillTypePageParam;
import com.evildog.workspace.invest.application.model.BillTypeListParam;
import com.evildog.workspace.invest.application.model.BillTypeParam;
import com.evildog.workspace.invest.application.vo.BillTypePageVO;
import com.evildog.workspace.invest.application.vo.BillTypeListVO;
import com.evildog.workspace.invest.application.vo.BillTypeVO;
import com.evildog.workspace.invest.application.bo.BillTypeBO;
import com.evildog.workspace.invest.application.bo.BillTypePageBO;
import com.evildog.workspace.invest.application.bo.BillTypeListBO;
import com.evildog.workspace.invest.application.convert.BillTypeConvert;
import com.evildog.workspace.invest.application.service.BillTypeService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * <p>
 * billType Controller
    账单类型
 * </p>
 *
 * @author evildog
 * @since 2020-08-06
 */
@RestController
@RequestMapping("/bill-types")
@AllArgsConstructor
@Api(tags = "billType相关接口")
public class BillTypeController {

    private BillTypeService billTypeService;

    @PostMapping
    @ApiOperation(value = "添加接口")
    public Result<Boolean> save(@RequestBody BillTypeParam billTypeParam) {
        return ResultGenerator.status(billTypeService.save(BillTypeConvert.INSTANCE.convert(billTypeParam)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(billTypeService.removeById(id));
    }

    @DeleteMapping("/batch-remove")
    @ApiOperation(value = "批量删除接口")
    public Result<Boolean> removeByIds(@RequestParam("ids") List<Integer> ids) {
        return ResultGenerator.status(billTypeService.removeByIds(ids));
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新接口")
    public Result<Boolean> updateById(@PathVariable("id") Long id,@RequestBody BillTypeParam billTypeParam) {
        return ResultGenerator.status(billTypeService.updateById(id, BillTypeConvert.INSTANCE.convert(billTypeParam)));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查询详情接口")
    public Result<BillTypeVO> getById(@PathVariable("id") Long id) {
        BillTypeBO billTypeBO = billTypeService.getDetailById(id);
        return ResultGenerator.success(BillTypeConvert.INSTANCE.convert(billTypeBO));
    }

    @GetMapping("/page")
    @ApiOperation(value = "表分页查询接口")
    public Result<PagedResult<BillTypePageVO>> getPageList(BillTypePageParam billTypePageParam, PageQuery query){
        PagedResult<BillTypePageBO> billTypePageBO = billTypeService.getPageList(
                        query,
                        QueryConditionUtils.getQueryCondition(billTypePageParam),
                        BillTypeConvert.INSTANCE.convert(billTypePageParam));
        return ResultGenerator.success(BillTypeConvert.INSTANCE.convert(billTypePageBO));
    }

    @GetMapping
    @ApiOperation(value = "表List查询接口")
    public Result<List<BillTypeListVO>> getList(BillTypeListParam billTypeListParam){
        List<BillTypeListBO> billTypeListBO = billTypeService.getList(
                        QueryConditionUtils.getQueryCondition(billTypeListParam),
                        BillTypeConvert.INSTANCE.convert(billTypeListParam));
        return ResultGenerator.success(BillTypeConvert.INSTANCE.convertVoList(billTypeListBO));
    }

}